<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SprayPaintingComponent;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SprayPaintingComponentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SprayPaintingComponent(), function (Grid $grid) {
            $grid->column('title');
            $grid->column('position_type')->using(admin_trans('spray-painting-component.options.position_type'));
            $grid->column('standard_quantity_base');
            $grid->column('performance_quantity_base');
            $grid->column('standard_working_base');
            $grid->column('performance_working_base');
            $grid->column('damage_light_coefficient');
            $grid->column('damage_centre_coefficient');
            $grid->column('damage_weight_coefficient');
            $grid->column('damage_new_coefficient');
            $grid->column('status')->using(admin_trans('spray-painting-component.options.status'));
            $grid->model()->where('type', COMPONENT_SPRAY_PAINT);

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('title');
                $filter->equal('position_type')->select(admin_trans('spray-painting-component.options.position_type'));
            });

            $grid->disableViewButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SprayPaintingComponent(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('position_type');
            $show->field('standard_quantity_base');
            $show->field('performance_quantity_base');
            $show->field('standard_working_base');
            $show->field('performance_working_base');
            $show->field('damage_light_coefficient');
            $show->field('damage_centre_coefficient');
            $show->field('damage_weight_coefficient');
            $show->field('damage_new_coefficient');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SprayPaintingComponent(), function (Form $form) {
            $form->display('id');
            $form->select('position_type')->options(admin_trans('spray-painting-component.options.position_type'));
            $form->text('title');
            $form->text('standard_quantity_base');
            $form->text('performance_quantity_base');
            $form->text('standard_working_base');
            $form->text('performance_working_base');
            $form->text('damage_light_coefficient');
            $form->text('damage_centre_coefficient');
            $form->text('damage_weight_coefficient');
            $form->text('damage_new_coefficient');
            $form->radio('status')->options(admin_trans('spray-painting-component.options.status'))->default('1');
            $form->hidden('type')->value(COMPONENT_SPRAY_PAINT);

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
